package com.menggudf.controller;


import com.menggudf.entity.CaseHistory;
import com.menggudf.model.ResultModel;
import com.menggudf.model.request.HistoryRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import com.menggudf.service.CaseHistoryService;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * 病历
 * @author Administrator
 *
 */
@Controller
@RequestMapping("caseHistory")
public class CaseHistoryController {
	
	@Autowired
	private CaseHistoryService caseHistoryService;
	/*	*//**
	 * 保存病历
	 * @param request
	 * @param response
	 *//*
	@RequestMapping("/tosave")
	@ResponseBody
	public ResultModel toSave(HttpServletRequest request,HttpServletResponse response,
			HttpSession httpSession,
//			@RequestParam(value="id",required=false) int id,
			@RequestParam(value="historyName",required=false) String historyName,
			@RequestParam(value="username",required=false) String username,
			@RequestParam(value="birthday",required=false) String birthday,
			@RequestParam(value="maritalStatus",required=false) String maritalStatus,
			@RequestParam(value="phone",required=false) String phone,
			@RequestParam(value="allergicHistory",required=false) String allergicHistory,
			@RequestParam(value="previousHistory",required=false) String previousHistory,
			@RequestParam(value="personalHistory",required=false) String personalHistory,
			@RequestParam(value="familyHistory",required=false) String familyHistory,
			@RequestParam(value="obstericalHistory",required=false) String obstericalHistory,
			@RequestParam(value="presentIllness",required=false) String presentIllness,
			@RequestParam(value="physicalExamination",required=false) String physicalExamination,
			@RequestParam(value="accessoryExamination",required=false) String accessoryExamination,
			@RequestParam(value="secondaryPassword",required=false) String secondaryPassword,
			@RequestParam(value="menstrualHistory",required=false) String menstrualHistory,
			@RequestParam(value="profession",required=false) String profession,
			@RequestParam(value="sex",required=false) String sex
			){
		UserModel user=(UserModel) httpSession.getAttribute("userModel");//获取session中用户
		CaseHistory bean;
		try {
			String id1=request.getParameter("id");
			int id=Integer.valueOf(id1);
		
			if(id!=0){//更新
				caseHistoryService.setEntityClass(CaseHistory.class);
				bean=(CaseHistory) caseHistoryService.get(id);
			}else{//新增
				bean=new CaseHistory();
			}
			bean.setAccessoryExamination(accessoryExamination);
			bean.setAllergicHistory(allergicHistory);
			bean.setBirthDay(birthday);
			bean.setFamilyHistory(familyHistory);
			bean.setHistoryName(historyName);
			bean.setMaritalStatus(maritalStatus);
			bean.setObstericalHistory(obstericalHistory);
			bean.setPersonalHistory(personalHistory);
			bean.setPresentIllness(presentIllness);
			bean.setPhone(phone);
			bean.setPhysicalExamination(physicalExamination);
			bean.setPreviousHistory(previousHistory);
			bean.setUsername(username);
			bean.setSecondaryPassword(secondaryPassword);
			bean.setUserCode(user.getUserCode());
			bean.setProfession(profession);
			bean.setMenstrualHistory(menstrualHistory);
			bean.setSex(Integer.valueOf(sex));
			caseHistoryService.saveOrUpdate(bean);
			return ResultModel.success();
		} catch (Exception e) {
			 
			e.printStackTrace();
		}
		return ResultModel.fail();
	}
	*//**
	 * 病历列表
	 * @param request
	 * @param response
	 * @return
	 *//*
	@RequestMapping("/toList")
	public ModelAndView toList(HttpServletRequest request,HttpServletResponse response,HttpSession httpSession){
		 ModelAndView mav=new ModelAndView("/jsp/caseHistory/caseHistoryList");
		 UserModel userModel=(UserModel) httpSession.getAttribute("userModel");//获取session中用户
		 List list= caseHistoryService.CaseList(userModel.getUserCode());
		 mav.addObject("list", list);
		 mav.addObject("size", list.size());
		return mav;
	}
	*//**
	 * 获取病历详情
	 * @param request
	 * @param response
	 * @return
	 *//*
	@RequestMapping("/toEditCaseDetail")
	public ModelAndView toEditCaseDetail(HttpServletRequest request,HttpServletResponse response,
			@RequestParam(value="id") int id){
		ModelAndView mav=new ModelAndView("/jsp/caseHistory/caseHistoryEdit");
		caseHistoryService.setEntityClass(CaseHistory.class);
		CaseHistory bean=(CaseHistory) caseHistoryService.get(id);
//		List list=caseHistoryService.CaseDetail(id);
		mav.addObject("bean", bean);
		return mav;
	}
	*//**
	 * 新建病历
	 * @param request
	 * @param response
	 * @return
	 *//*
	@RequestMapping("/addCase")
	public ModelAndView addCase(HttpServletRequest request,HttpServletResponse response){
		ModelAndView mav =new ModelAndView("/jsp/caseHistory/caseHistoryEdit");
		mav.addObject("id", 0);
		return mav;
	}*/

	/**
	 * 生成病史接口
	 * @param historyRequest
	 * @return
	 */
	@RequestMapping("createHistory")
	@ResponseBody
	public ResultModel createHistory(@RequestBody HistoryRequest historyRequest){
		CaseHistory caseHistory = new CaseHistory();
		caseHistory.setAllergicHistory(historyRequest.getAllergicHistory());
		caseHistory.setFamilyHistory(historyRequest.getFamilyHistory());
		caseHistory.setPreviousHistory(historyRequest.getPreviousHistory());

		caseHistoryService.toSaveCaseHis(caseHistory);
		return ResultModel.success();
	}

}
	 